﻿using System.Windows;
using System.Windows.Input;

namespace hr_1.ViewModel
{
    public class AllPersonDataViewModel: ViewModelBase
    {
        RelayCommand _saveCommand;
        readonly PersonViewModel _personViewModel = new PersonViewModel();
        readonly PersonalDocViewModel _personalDocViewModel = new PersonalDocViewModel();
        readonly PersonalInfoViewModel _personalInfoViewModel = new PersonalInfoViewModel();
        readonly EducationMilitaryViewModel _educationMilitaryViewModel = new EducationMilitaryViewModel();
        readonly WorkActivityViewModel _workActivityViewModel = new WorkActivityViewModel();

        #region AllPersonDataViewModel Properties

        public PersonViewModel Person
        {
            get { return _personViewModel; }
        }
        public PersonalDocViewModel PersonalDoc
        {
            get { return _personalDocViewModel; }
        }
        public PersonalInfoViewModel PersonalInfo
        {
            get { return _personalInfoViewModel; }
        }
        public EducationMilitaryViewModel EducationMilitary
        {
            get { return _educationMilitaryViewModel; }
        }
        public WorkActivityViewModel WorkActivity
        {
            get { return _workActivityViewModel; }
        }

        #endregion // AllPersonDataViewModel Properties

        #region Presentation Properties

        public ICommand SaveCommand
        {
            get
            {
                if (_saveCommand == null)
                {
                    _saveCommand = new RelayCommand(
                        param => this.Save()
                        );
                }
                return _saveCommand;
            }
        }

        #endregion // Presentation Properties

        public void Save()
        {
            _personalDocViewModel.Save();
            _personalInfoViewModel.Save();
            _workActivityViewModel.Save();

            _personViewModel.PersonalDocId = _personalDocViewModel.PersonalDocId;
            _personViewModel.PersonalInfoId = _personalInfoViewModel.PersonalInfoId;
            _personViewModel.WorkActivityId = _workActivityViewModel.WorkActivityId;
            _personViewModel.Save();

            _educationMilitaryViewModel.PersonId = _personViewModel.PersonId;
            _educationMilitaryViewModel.Save();

            MessageBox.Show("Новый сотрудник успешно сохранен в базу данных.");
        }
    }
}
